<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [1, 1, 2, 2, 3, 4, 4, 2, 1, 4, 5, 6, 5];
      //第一种用indexof
      function norepeat_index(arr) {
        var newarr = [];
        for (i = 0; i < arr.length; i++) {
          if (newarr.indexOf(arr[i]) == -1) {
            newarr.push(arr[i]);
          }
        }
        return newarr;
      }
      //第二种利用键名不能重复
      function norepeat_obj(arr) {
        var obj = new Object();
        for (i = 0; i < arr.length; i++) {
          obj[arr[i]] = arr[i];
        }
        return obj;
      }
      //set集合的值不重复
      function norepeat_set(arr) {
        var set = new Set();
        for (i = 0; i < arr.length; i++) {
          set.add(arr[i]);
        }
        var res = Array.from(set);
        return res;
      }

      console.log(norepeat_index(arr));
      console.log(norepeat_obj(arr));
      console.log(norepeat_set(arr));
    </script>
  </body>
</html>
